<?php
namespace admin\model;
use \temmoku\model;
class articles extends model{
	
   	public function title($post,$step='post')
    {
		
    	$array=[
		    'cid'=>$post['cid'],
		    'name'=>$post['name'],
		    'mid'=>$post['mid'],
		    'uid'=>$post['uid'],
		    'username'=>$post['username'],
		    'state'=>$post['state'],
		    'state_time'=>$post['state_time'],
		    'title'=>$post['title'],
		    'seotitle'=>$post['seotitle'],
		    'color'=>$post['color'],
		    'bold'=>$post['bold'],
		    'keyword'=>$post['keyword'],
		    'description'=>$post['description'],
		    'author'=>$post['author'],
		    'source'=>$post['source'],
		    'source_url'=>$post['source_url'],
		    'thumb'=>$post['thumb'],
		    'is_pic'=>$post['is_pic'],
		    'posttime'=>$post['posttime'],
		    'clicks'=>$post['clicks'],
		    'password'=>$post['password'],
		    'sell_jifen'=>$post['sell_jifen'],
		    'is_comment'=>$post['is_comment'],
		];
		if('post'===$step){
			$array['reorder']=NOWTIME;
			$aid = $this->insert(jab."article")->cols($array)->query();
		}else{
			$this->update(jab."article")->cols($array)->where("aid=$post[aid]")->query();
		}
    	
		return $aid;
    }

	public function content($post,$step='post'){
		if('post'===$step){
			$content=[
				'aid'=>$post['aid'],
				'content'=>$post['content']
			];
			$this->insert(jab."content")->cols($content)->query();	
		}else{
			$this->update(jab."content")->cols(['content'=>$post['content']])->where("nid='{$post[nid]}'")->query();
		}
	}
    public function module($aid,$mid,$data,$step='post'){
		if("post"===$step){
			$data['aid']=$aid;
			$this->insert(jab."content_$mid")->cols($data)->query();
		}else{
			$module=$this->select('*')->from(jab."content_$mid")->where("aid=$aid")->row();
			if($module){
				$this->update(jab."content_$mid")->cols($data)->where("aid=$aid")->query();
			}else{
				$article=$this->select('*')->from(jab."article")->where("aid=$aid")->row();
				//等于0 说明以前没有发布
				if('0' == $article['mid']){
					$data['aid']=$aid;
					$this->insert(jab."content_$mid")->cols($data)->query();
				}
			}
		}
	}
    
}